package org.istt.domain;

import static javax.persistence.GenerationType.IDENTITY;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;

import org.hibernate.annotations.Type;
import org.joda.time.DateTime;

/**
 * FileManagement entity. @author MyEclipse Persistence Tools
 */
@Entity(name="fileMgr")
@Table(name = "TBL_FILE_MANAGEMENT", schema = "dbo", catalog = "onegate")
public class FileManagement extends BaseObject<Long> implements java.io.Serializable {

	// Fields

	/**
	 * 
	 */
	private static final long serialVersionUID = -8863941216645563937L;
	private Boolean activeStatus;
	private String approvedComment;
	private DateTime approvedDate;
	private User approver;
	private Boolean approveStatus;
	private File file;
	private Long id;
	private DateTime receivedDate;
	//Added by NDTHO.2012.03.06
	private User receiverRejectFile;
	private User sender;
	
	//Added by NDTHO.2012.02.18
	private Boolean viewStatus;
	
	private WorkflowProcess workflowProcess;
	
	// Constructors

	/** default constructor */
	public FileManagement() {
	}

	@Override
	public boolean equals(Object o) {
		if (this == o) return true;
		if (!(o instanceof FileManagement)) return false;

		final FileManagement ps = (FileManagement) o;

        if (!getId().equals(ps.getId())) return false;

		return true;
	}

	@Column(name="ACTIVE_STATUS")
	public Boolean getActiveStatus() {
		return activeStatus;
	}

	/**
	 * @return the approvedComment
	 */
	@Column(name = "APPROVED_COMMENT", length = 1000)
	public String getApprovedComment() {
		return approvedComment;
	}
	
	/**
	 * @return the approvedDate
	 */
	@Column(name = "APPROVED_DATE")
	@Type(type="org.joda.time.contrib.hibernate.PersistentDateTime")
	public DateTime getApprovedDate() {
		return approvedDate;
	}

	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumn(name = "APPROVER_ID")
	/**
	 * @return the approver
	 */
	public User getApprover() {
		return approver;
	}

	@Column(name="APPROVE_STATUS")
	public Boolean getApproveStatus() {
		return approveStatus;
	}

	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumn(name = "FILE_ID")
	public File getFile() {
		return this.file;
	}

	// Property accessors
	@Id
	@GeneratedValue(strategy = IDENTITY)
	@Column(name = "ID", unique = true, nullable = false)
	public Long getId() {
		return this.id;
	}

	/**
	 * @return the receivedDate
	 */
	@Column(name = "RECEIVED_DATE")
	@Type(type="org.joda.time.contrib.hibernate.PersistentDateTime")
	public DateTime getReceivedDate() {
		return receivedDate;
	}

	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumn(name = "RECEIVER_REJECT_FILE")
	public User getReceiverRejectFile() {
		return receiverRejectFile;
	}

	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumn(name = "SENDER_ID")
	/**
	 * @return the sender
	 */
	public User getSender() {
		return sender;
	}

	@Column(name = "VIEW_STATUS")
	public Boolean getViewStatus() {
		return viewStatus;
	}
	
	@ManyToOne(fetch=FetchType.LAZY)
	@JoinColumn(name="WORKFLOW_PROCESS_ID")
	/**
	 * @return the workflowProcess
	 */
	public WorkflowProcess getWorkflowProcess() {
		return workflowProcess;
	}

	@Override
	public int hashCode() {
		int result;
		result = id.hashCode();
		result = 29 * result;
		return result;
	}

	public void setActiveStatus(Boolean activeStatus) {
		this.activeStatus = activeStatus;
	}
	
	/**
	 * @param approvedComment the approvedComment to set
	 */
	public void setApprovedComment(String approvedComment) {
		this.approvedComment = approvedComment;
	}


	/**
	 * @param approvedDate the approvedDate to set
	 */
	public void setApprovedDate(DateTime approvedDate) {
		this.approvedDate = approvedDate;
	}

	/**
	 * @param approver the approver to set
	 */
	public void setApprover(User approver) {
		this.approver = approver;
	}

	public void setApproveStatus(Boolean approveStatus) {
		this.approveStatus = approveStatus;
	}


	public void setFile(File file) {
		this.file = file;
	}


	public void setId(Long id) {
		this.id = id;
	}


	/**
	 * @param receivedDate the receivedDate to set
	 */
	public void setReceivedDate(DateTime receivedDate) {
		this.receivedDate = receivedDate;
	}

	public void setReceiverRejectFile(User receiverRejectFile) {
		this.receiverRejectFile = receiverRejectFile;
	}

	/**
	 * @param sender the sender to set
	 */
	public void setSender(User sender) {
		this.sender = sender;
	}

	public void setViewStatus(Boolean viewStatus) {
		this.viewStatus = viewStatus;
	}

	/**
	 * @param workflowProcess the workflowProcess to set
	 */
	public void setWorkflowProcess(WorkflowProcess workflowProcess) {
		this.workflowProcess = workflowProcess;
	}

	@Override
	public String toString() {
		return new StringBuilder()
					.append("fileId: " + getFile().getId())
					.append("workflow position: " + getWorkflowProcess().getPosition())
					.toString();
	}

	
}